package com.taxshare.operation.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.taxshare.operation.entity.ResourceEntity;
import com.taxshare.operation.mapper.ResourceInitConfigMapper;
import com.taxshare.operation.mapper.ResourceMapper;
import com.taxshare.tools.util.UUIDUitl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: ResourceInitConfig
 * @Description:
 * @author: luozhongyi
 * @date: 2021/3/4 14:26
 */
@Service
public class ResourceInitConfigService extends ServiceImpl<ResourceMapper, ResourceEntity> {

    @Autowired
    ResourceInitConfigMapper resourceInitConfigMapper;
    /**
     * 初始化系统
     */
    public void init(){
        //初始化资源菜单
        initResource();
        //初始化集团和账号信息
        initAccount();

    }
    /**
     *  初始化系统菜单资源
     */
    private void initResource(){
        QueryWrapper<ResourceEntity> queryWrapper = new QueryWrapper();
        queryWrapper.eq("resource_code","yygl");
        if(baseMapper.selectCount(queryWrapper) == 0) {
            //系统管理
            ResourceEntity systemEntity = new ResourceEntity();
            systemEntity.setResourceId(UUIDUitl.UUID32(false));
            systemEntity.setResourceCode("xtgl");
            systemEntity.setResourceIcon("icon-xitongguanli");
            systemEntity.setResourceName("系统管理");
            systemEntity.setResourceType("T001");
            systemEntity.setResourceParentId("0");
            systemEntity.setResourceUrl("/xtgl");
            systemEntity.setResourceSort(5);
            baseMapper.insert(systemEntity);
            //运营管理
            ResourceEntity operationEntity = new ResourceEntity();
            operationEntity.setResourceId(UUIDUitl.UUID32(false));
            operationEntity.setResourceCode("yygl");
            operationEntity.setResourceIcon("icon-yunyingguanli");
            operationEntity.setResourceName("运营管理");
            operationEntity.setResourceType("T001");
            operationEntity.setResourceParentId("0");
            operationEntity.setResourceUrl("/yygl");
            operationEntity.setResourceSort(6);
            baseMapper.insert(operationEntity);
            //菜单管理
            ResourceEntity resourceEntity = new ResourceEntity();
            resourceEntity.setResourceId(UUIDUitl.UUID32(false));
            resourceEntity.setResourceCode("cdgl");
            resourceEntity.setResourceIcon("icon-caidanguanli");
            resourceEntity.setResourceName("菜单管理");
            resourceEntity.setResourceType("T001");
            resourceEntity.setResourceParentId(operationEntity.getResourceId());
            resourceEntity.setResourceUrl("/yygl/cdgl");
            resourceEntity.setResourceSort(1);
            baseMapper.insert(resourceEntity);
            //权限管理
            ResourceEntity authEntity = new ResourceEntity();
            authEntity.setResourceId(UUIDUitl.UUID32(false));
            authEntity.setResourceCode("qxgl");
            authEntity.setResourceIcon("icon-quanxianguanli");
            authEntity.setResourceName("权限管理");
            authEntity.setResourceType("T001");
            authEntity.setResourceParentId(systemEntity.getResourceId());
            authEntity.setResourceUrl("/qxgl");
            authEntity.setResourceSort(1);
            baseMapper.insert(authEntity);
            //角色管理
            ResourceEntity roleEntity = new ResourceEntity();
            roleEntity.setResourceId(UUIDUitl.UUID32(false));
            roleEntity.setResourceCode("jsgl");
            roleEntity.setResourceIcon("icon-quanxianguanli");
            roleEntity.setResourceName("角色管理");
            roleEntity.setResourceType("T002");
            roleEntity.setResourceParentId(authEntity.getResourceId());
            roleEntity.setResourceUrl("/xtgl/jsgl");
            roleEntity.setResourceSort(2);
            baseMapper.insert(roleEntity);
            //用户管理
            ResourceEntity userEntity = new ResourceEntity();
            userEntity.setResourceId(UUIDUitl.UUID32(false));
            userEntity.setResourceCode("yhgl");
            userEntity.setResourceIcon("");
            userEntity.setResourceName("用户管理");
            userEntity.setResourceType("T002");
            userEntity.setResourceParentId(authEntity.getResourceId());
            userEntity.setResourceUrl("/xtgl/yhgl");
            userEntity.setResourceSort(1);
            baseMapper.insert(userEntity);
        }
    }

    /**
     * 初始化账号
     */
    private void initAccount(){

        //1.新建一个type为2得超级管理员
        //2.新建一个超级管理员角色
        //3.给超级管理员角色绑定菜单
    }
}
